package com.imchen.demov4;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Looper;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.Button;
import android.widget.Toast;

import com.applovin.mediation.MaxAd;
import com.applovin.mediation.MaxAdFormat;
import com.applovin.mediation.ads.MaxAdImpl;
import com.applovin.mediation.ads.ShowAds;
import com.ironsource.mediationsdk.model.Placement;
import com.kuaiyouxi.gamepad.sdk.shell.assist.SDKAssist;

/**
 * @Description
 * @Author imchen
 * @CreateTime 2019/6/6 11:42
 */
public class Demo  extends Activity implements RewardItem {

    public static Context gContext;
    public static  Activity mActivity;
    private static final String  TAG="Demo";
    public  static boolean sShouldShowReward =false;
    private Button btn;
    private ShowAds mShowAds;
    private static boolean isDebug = true;
    private static String sStr;
    private static int mAge=0;

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            Log.d("aa", "onKeyDown: ");
        }
        Log.d("bbb", "onKeyDown: ");
        return false;

    }



    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        int action = event.getAction();
        if (action == KeyEvent.ACTION_DOWN) {
            if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
                Log.d("aa", "onKeyDown: ");
            }
            Log.d("bbb", "ACTION_DOWN: ");
        }
        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Looper.prepare();
        Log.d("onKeyDown", "run: ");
        Looper.loop();
        return false;
    }

    public static void printUnity(Class clz,String s1,String s2,boolean is){
        Log.e("imchen","class; "+clz.getName()+" s1: "+s1+" s2: "+s2+" bol: "+is);
    }

    public static void showAlert(Activity activity,String msg){
        AlertDialog.Builder builder=new AlertDialog.Builder(activity);
        builder.setTitle("提示");
        builder.setMessage(msg);
        builder.setNegativeButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
                dialog.dismiss();
            }
        });
        builder.create().show();
    }

    public static void showToast(Activity activity,String msg){
        Toast.makeText(activity,msg,Toast.LENGTH_SHORT
        ).show();
        Context context=SmaliExample.mContext;
        if (context!=null){
            Log.d("req", "showToast: ");
        }
    }

    public void testa(String location, int  reward){


        if (getApplicationContext()!=null){
            Log.d("test", "testa: ");
        }else{
            Log.e("test", "testa: " );
        }
        Log.d("test", "testa: "+"location: "+location+" reward: "+reward);
        ((TestInstance) TestInstance.getInstance()).show();
        TestInstance.mInstance.show();
        gContext=getApplicationContext();
        mActivity=this;

    }

    public void dialogTest(){
        AlertDialog.Builder builder=new AlertDialog.Builder(this);
        builder.setNegativeButton("", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });

        gContext.getAssets();
        testAct((Activity) getApplicationContext());
    }

    public void testAct(Activity activity){
        activity.getSharedPreferences("aa",Context.MODE_PRIVATE);
    }

    public void openPrivacy(){
        Uri uri = Uri.parse("https://www.baidu.com");
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        getApplicationContext().startActivity(intent);
    }

    public void castInt(){
        int a = 132;
        Log.d(TAG, "castInt: "+a);


        if (sShouldShowReward){
            openPrivacy();
            return;
        }
        a = 132;
    }

    public void btnSetText(){
        btn.setText("1234");
        btn.setTextScaleX(0.8f);

    }

    private void createMaxAd(String uid){
        MaxAd maxAd=new MaxAdImpl("123", MaxAdFormat.REWARDED,true);
        mShowAds.onAdCompleted(maxAd);
        mShowAds.showInterstitial(maxAd);
    }

    private void onAdLoaded(MaxAd maxAd){
        setEnableDebug(false);
    }

    private  void setEnableDebug(boolean isDebug){

    }


    private void floatTest(float arg){
        float f1=1.0f;

    }

    private Double testDouble(Double d){
        double a =1.2;
        sStr = "1234";
        return a;
    }

    private void setString(String age,int amout){
        String name =age;
        age="1234";
        System.out.println(age+amout);
        String page=age;
        int xxx=amout;
        this.createPlacementObj();
    }

    private Placement createPlacementObj(){
        Placement placement=new Placement(0,"DefaultRewardedVideo","Virtual Item",1,null);
        return placement;
    }

    public static void ifel(String arg0){
        if ("retry-ad".equals(arg0)){
            return;
        }
        showAlert(mActivity,"");
    }

    public void setName(String age){
        int  iAge = Integer.parseInt(age);
    }

    public void setAge(int age ){
        Log.d("imchen","age: "+age);
        if (age>10000){
            mAge=age;
        }else {
            SDKAssist.showLog();
        }
    }

    public boolean isOfferwallAvailable(){
        return RegularAd.showReward(String.valueOf(mAge));
    }

    public RewardItem getRewardItem(){
        return new Demo();
    }


    @Override
    public int getAmount() {
        return 0;
    }

    @Override
    public String getType() {
        return null;
    }


    public static void printArgs(String appId){
        if (appId!=null){

        Log.e("imchen","appId: "+appId);
        }

    }

    public static void saveUnlock(Context context,String key){

    }
}
